package com.offcn.search.controller;

import com.offcn.common.entity.Result;
import com.offcn.common.entity.StatusCode;
import com.offcn.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * Search控制层
 *
 * @author 30389
 * CrossOrigin  跨域注解
 */
@RestController
@RequestMapping("search")
@CrossOrigin
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 触发实现远程调用 sellergoods微服的数据
     *
     * @return
     */
    @GetMapping("importData")
    public Result importData() {
        searchService.importData();
        return new Result(true, StatusCode.OK, "导入成功");
    }

    /**
     * 前端页面向此处发来查询请求，并没有带关键字
     *
     * @return
     */
    @GetMapping("search")
    public Result search(@RequestParam(required = false) Map<String, String> searchMap) {
        Map<String, Object> map = searchService.search(searchMap);
        return new Result(true, StatusCode.OK, "搜索成功",map);
    }



}
